#ifndef _NetworkManager
#define _NetworkManager

#include "ConnectionManager.h"

#define NETWORK_BUFLEN 2048


class NetworkManager {

public:
	ConnectionManager *cm;
	HANDLE hReady;		// Used to set isReady event

	// Constructor
	NetworkManager();
	// Deconstructor
	~NetworkManager();
	
	// Allocates a new connection
	Connection* add();
	// Deallocates a connection
	bool del(Connection* /*conn*/);

	// does nothing if socket is already enabled, otherwise tries to connect
	bool start(Connection* /*conn*/);

	bool isReady();			// non-blocking check for network activity
	void waitForReady();	// blocking check for network activity
	bool isNew();	// one or more new connections have been established
	bool isDel();	// one or more existing connections have closed
	bool isData();	// one or more existing connections have data

	// with each call returns a new connection & disables the new flag
	Connection* getNewConnection();
	// with each call returns a del connection & disables the new flag
	Connection* getDelConnection();
	// with each call returns a data connection & disables the new flag
	Connection* getDataConnection();

	// causes waitForReady to immediately return
	void triggerWaitForReady();

	// writes to all socket connections on the specified port
	void write(char* /*data*/, char* /*value*/, char* /*bytes*/);
	void write(char* /*data*/, char* /*value*/, char* /*bytes*/, int /*count*/);
};

#endif // _NetworkManager